package evolution.problem;

import static java.lang.Math.abs;
import static java.lang.Math.sin;
import static java.lang.Math.sqrt;

public class SchwefelMinimization extends AbstractMinimizationProblem {

	public static final ProblemConstraints CONSTRAINTS = new ProblemConstraints(
			2, -500, 500);

	public SchwefelMinimization() {
		super(CONSTRAINTS);
	}

	/**
	 * <a href>http://www.aridolan.com/ga/gaa/Schwefel.html</a>
	 */
	@Override
	public double getValue(double[] x) {
		double n = x.length;
		double sum = 418.9829 * n;
		for (int i = 0; i < n; i++) {
			double x_i = x[i];
			sum -= x_i * sin(sqrt(abs(x_i)));
		}

		return sum;
	}

	@Override
	public String getGnuplotFunction() {
		return "418.9829*2 - x*sin(sqrt(abs(x))) - y*sin(sqrt(abs(y)))";
	}

	@Override
	public String getGnuplotFunctionName() {
		return "schwefel";
	}
}
